package file.day9_20.day05.构建服务端与客户端练习;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    private ServerSocket serverSocket;

    public Server(){
        System.out.println("服务端正在启动");

        try {
            serverSocket = new ServerSocket(8089);
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("服务端启动完成");
    }

    public void start(){
        try {
            System.out.println("等待客户端连接");

            Socket socket = serverSocket.accept();

            System.out.println("客户端连接完成");
            BufferedReader br = new BufferedReader(
                    new InputStreamReader(
                            socket.getInputStream(),"UTF-8"
                    )
            );

            String line = null;
            while ((line = br.readLine()) != null){
                System.out.println("客户端说："+line);
            }



        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }
}
